package com.zhihui.online.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhihui.online.dto.student.StudentPageDTO;
import com.zhihui.online.entity.Student;
import com.zhihui.online.exception.MyCustomerException;
import com.zhihui.online.mapper.StudentMapper;
import com.zhihui.online.service.StudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhihui.online.utils.ResultCodeEnum;
import com.zhihui.online.vo.StudentVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 学生表 服务实现类
 * </p>
 *
 * @author 程序员阿良,21岁纯情后爸,懒得想名字
 * @since 2024-08-01
 */
@Service
@Transactional
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Override
    public void updateStatus(Long id, Integer status) {
        Student student=this.baseMapper.selectById(id);
        student.setStatus(status);
        this.baseMapper.updateById(student);
    }


    @Override
    public IPage<StudentVO> selectPage(IPage<StudentVO> ipage, StudentPageDTO studentPageDto) {
        IPage<StudentVO> studentIPage = this.baseMapper.selectPage(ipage, studentPageDto);
        return studentIPage;
    }

    @Override
    public StudentVO getVo(Student student) {
        if (student == null) {
            throw  new MyCustomerException(ResultCodeEnum.USER_NOT_EXIST);
        }
        //拷贝对象
        StudentVO studentVo = new StudentVO();
        BeanUtils.copyProperties(student, studentVo);
        return studentVo;

    }




}
